﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Maticsoft.Common.DEncrypt;

namespace Maticsoft.Web.ashx
{
    /// <summary>
    /// user 的摘要说明
    /// </summary>
    public class user : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string mobile = context.Request.QueryString["mobile"];
            string ope = context.Request.QueryString["ope"];
            if (ope == "view")
            {
                BLL.Members meBLL = new BLL.Members();
                Model.Members meModel = meBLL.GetModel(mobile);
                if (meModel != null && meModel.Status > 0)
                {
                    context.Response.Write("1");
                    context.Response.End();
                }

                context.Response.Write("-1");
                context.Response.End();
            }
            else if (ope == "reset")
            {
                string code = context.Request.QueryString["code"];
                string pass = context.Request.QueryString["pwd"];
                BLL.Members meBLL = new BLL.Members();
                Model.Members meModel = meBLL.GetModel(mobile);
                if (meModel == null || meModel.Status == 0)
                {
                    context.Response.Write("-1");
                    context.Response.End();
                }

                BLL.SendMsg msgBLL = new BLL.SendMsg();
                List<Model.SendMsg> list = msgBLL.GetListByMobile(mobile);
                if (list.Count > 0)
                {
                    Model.SendMsg msgModel = list[0];
                    if (msgModel.VerifyCode != code)
                    {
                        context.Response.Write("-2");
                        context.Response.End();
                    }

                    if (((DateTime)msgModel.CreateTime).AddMinutes(10) < DateTime.Now)
                    {
                        context.Response.Write("-3");
                        context.Response.End();
                    }
                }

                meModel.Password = DEncrypt.Encrypt(pass);
                meModel.UpdateTime = DateTime.Now;
                meBLL.Update(meModel);

                context.Response.Write("1");
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}